# gen_circle.py

from __future__ import division

import math
from optparse import OptionParser

from ot_simulator.template.template_funs import frange

def to_polar(x, y):
    r = math.hypot(x, y)
    theta = math.atan2(y, x)
    return r, theta

def repeat(seq, num_repeats):
    seq = tuple(seq)
    for i in xrange(num_repeats):
        for r, theta in seq:
            yield r, (theta + i * 360.0) / num_repeats

def gen_circle(radius, offset, inc=1):
    for angle in frange(inc, 0, 360 - inc):
        angle_radians = math.radians(angle)
        c, s = math.cos(angle_radians), math.sin(angle_radians)
        circle_x, circle_y = radius * c, radius * s
        offset_x, offset_y = x + offset[0], y + offset[1]
        yield to_polar(offset_x, offset_y)

def gen_line(start, end, inc):
    r'''Generates points along a line.

        >>> for x, y in gen_line((1.0, 2.0), (2.0, 3.0), 0.25): print x, y
        1.0 2.0
        1.25 2.25
        1.5 2.5
        1.75 2.75
        2.0 3.0
    '''
    start_x, start_y = start
    end_x, end_y = end
    for x in frange(inc, start_x, end_x):
        yield x, (x - start_x) / (end_x - start_x) * (end_y - start_y) + start_y

def gen_polygon(num_sides, offset, inc=0.01):
    pass
